package com.huawei.translate.vo.translate;

import com.huawei.translate.utils.SystemConfig;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.List;

public class TranslateRequest extends TranslateBaseRequest {

    private String text;

    public TranslateRequest() {
    }

    public TranslateRequest(String accessToken, String from, String to, String text) {
        this.setAccessToken(accessToken);
        this.setFrom(from);
        this.setTo(to);
        this.text = text;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public boolean shouldDispatchtoMS() {
        if (!shouldDispatchToOthers()) {
            return true;
        }
        return false;
    }

    public boolean shouldDispatchToOthers() {
        List<String> languages = Arrays.asList(SystemConfig.getProperty("route.languages", "").split(","));
        if (languages.contains(getFrom()) && languages.contains(getTo())) {
            return true;
        }
        return false;
    }

    public boolean isValid() {
        return StringUtils.isNotEmpty(getAccessToken()) && StringUtils.isNotEmpty(getTo()) && StringUtils.isNotEmpty(text);
    }
}
